import codecs
import os
import sys


CARCONFIG_START = 1
CARCONFIG_END = 1000
AUTOGEN_FOLDER = "../../data"


def convertCarconfigValue(ccLists):
    carConfigs = []
    if len(ccLists) > 0:
        for ccIndex in range(len(ccLists)):
            carConfigs.append(
                "            case %s:\n                notification.%s = values[i];\n                break;\n" % (
                str(ccIndex).strip(), ccLists[ccIndex]))
    return ''.join(carConfigs)


if __name__ == "__main__":
    ccList = []
    for index in range(CARCONFIG_START, CARCONFIG_END):
        ccName = "carconfig" + str(index).strip()
        ccList.append(ccName)

    convertCarconfigContent = []
    convertCarconfigContent.append(convertCarconfigValue(ccList))

    with codecs.open(os.path.join(os.path.dirname(__file__), "Module.cpp.skeleton"), "r",
                     encoding="utf-8") as fr:
        skeletonFileContents = fr.read()
        cppContents = skeletonFileContents.replace("##convertCarconfigContent##",
                                                    '\n'.join(convertCarconfigContent))

    path = os.path.join(os.path.dirname(__file__), AUTOGEN_FOLDER)
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)

    filename = path+"/CarConfig.cpp"
    with codecs.open(filename, "w", encoding="utf-8") as fw:
        fw.write(cppContents)
        fw.close()
